<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="box"></div>
<script>

// 设计一个构造函数, 它的对象表示一本书, 每本书包含作者, 出版社, 出版日期.
// 显示这个本书的信息.   并能计算这本书到现在已经出版了多少天
function Book(author, bookName, publisher, publishTime){
    this.author = author;
    this.publisher = publisher;
    this.publishTime = publishTime;
    this.bookName = bookName;
    this.showMsg = function (div){
        div.innerHTML = this.getMsg();
    }
    this.getMsg = function (){
        return  "书名:" + this.bookName
                + "<br>作者:" + this.author
                + "<br>出版社:" + this.publisher
                + "<br>出版日期:" + this.publishTime.toLocaleString()
                + "<br>距离现在已经:" + this.calculateDate() + " 天"
    }
    this.calculateDate = function (){
        var now = new Date();
        var delta = now.getTime() - this.publishTime.getTime();
        return parseInt(delta / 1000 / 60 / 60 / 24);
    }
}
var b1 = new Book("东方不败", "葵花宝典", "江湖出版社", new Date(2000, 3, 4))
b1.showMsg(document.getElementById("box"))
</script>
</body>
</html>
